package cn.itcast.netty.c4;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;

import static cn.itcast.netty.c4.TestByteBuf.log;

public class TestSlice {
    public static void main(String[] args) {
        ByteBuf buf= ByteBufAllocator.DEFAULT.buffer(10);
        buf.writeBytes(new byte[]{'a','b','c','d','e','f','g','h','i','j'});
        log(buf);

        //在切片过程中没有产生数据复制
        ByteBuf f1=buf.slice(0,5);
        ByteBuf f2=buf.slice(5,5);
        f1.retain();
        log(f1);
        log(f2);

        System.out.println("释放了原有的内存空间");
        buf.release();
        log(f1);

        /*System.out.println("=========================");
        f1.setByte(0,'b');
        //验证物理内存是一体的
        log(f1);
        log(buf);*/
    }
}
